package by.grsu.hdm.devices;

import java.util.Random;

import by.grsu.hdm.model.HomeDevice;
import by.grsu.hdm.model.INetworkAvailable;
import by.grsu.hdm.model.IUsbPort;
import by.grsu.hdm.model.IUsbSupport;
import by.grsu.hdm.model.UsbPort;

public class MediaCenter extends HomeDevice implements IUsbSupport, INetworkAvailable {
	
	private long trafficIn;
	private long trafficOut;
	private int powerStatus; //Truing to include status of this device
	private UsbPort usbPort;
	
	protected MediaCenter() {
		defaultConfiguration();
	}
	
	public MediaCenter(String id) {
		super(id);
		
		defaultConfiguration();
	}
	
	protected void defaultConfiguration()
	{
		this.trafficIn = 0;
		this.trafficOut = 0;
		this.powerStatus = 0;  // In the default configuration the device is OFF(0)
		this.usbPort = null;
	}
	
	@Override
	public long getOutgoingTraffic() {
		return this.trafficOut;
	}
	
	@Override
	public long getIncomingTraffic() {
		return this.trafficIn;
	}

	@Override
	protected void afterTurningOn() {
		this.trafficIn = Math.abs(new Random().nextInt());
		this.trafficOut = Math.abs(new Random().nextInt());
		this.powerStatus = 1;    // when the device is on, setting powerStatus in 1
	}

	@Override
	protected void beforeTurningOff() {
		defaultConfiguration();
	}

	@Override
	public IUsbPort getUsbPort() {
		if (this.usbPort == null) { 
			this.usbPort = new UsbPort("USB-" + getDeviceId());
		}
		
		return this.usbPort;
	}
	public int getpowerStatus (){    //here we are getting status of media center
		return this.powerStatus;
		
	}
}
